#include "secondwidget.h"
#include "firstwidget.h"
#include <QDebug>

SecondWidget::SecondWidget(QWidget *parent) : QWidget(parent)
{
    this->setGeometry(0, 0, 800, 480);

    hWidget = new QWidget(this);
    hWidget->setGeometry(0, 0, 800, 240);

    vWidget = new QWidget(this);
    vWidget->setGeometry(0, 240, 800, 240);

    hLayout = new QHBoxLayout();
    vLayout = new QVBoxLayout();

    QList<QString> mList;
    mList << "one" << "two" << "three" << "four" << "five" << "six";

    for (int i = 0; i < mList.size(); i++) {
        mPushButton[i] = new QPushButton();
        mPushButton[i]->setText(mList.at(i));
        if (i < mList.size() / 2) {
            hLayout->addWidget(mPushButton[i]);
        }
        else {
            vLayout->addWidget(mPushButton[i]);
        }
        connect(mPushButton[i], &QPushButton::clicked,
                this, &SecondWidget::onClickListener);
    }
    hLayout->setSpacing(50);

    hWidget->setLayout(hLayout);
    vWidget->setLayout(vLayout);
}

void SecondWidget::onClickListener()
{
    QPushButton* button = dynamic_cast<QPushButton*>(sender());
    qDebug() << button->text();

    if (button->text() == "one") {
        FirstWidget* w = new FirstWidget();
        w->show();
    }
}
